home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / DRAW.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  5KB  |  295 lines

  1. #include "vogl.h"
  2.  
  3. /*
  4.  * draw
  5.  *
  6.  * draw a line form the logical graphics position to the
  7.  * the world coordinates x, y, z.
  8.  *
  9.  */
  10. void
  11. draw(x, y, z)
  12.     double        x, y, z;
  13. {
  14.     Token    *tok;
  15.     int    vx, vy;
  16.     Vector    res;
  17.  
  18.  
  19.     if (!vdevice.initialised)
  20.         verror("draw: vogl not initialised");
  21.  
  22.     if (vdevice.inobject) {
  23.         tok = newtokens(4);
  24.  
  25.         tok[0].i = DRAW;
  26.         tok[1].f = x;
  27.         tok[2].f = y;
  28.         tok[3].f = z;
  29.  
  30.         vdevice.cpW[V_X] = x;
  31.         vdevice.cpW[V_Y] = y;
  32.         vdevice.cpW[V_Z] = z;
  33.  
  34.         vdevice.cpVvalid = 0;
  35.  
  36.         return;
  37.     }
  38.  
  39.     if (!vdevice.cpVvalid)
  40.         multvector(vdevice.cpWtrans, vdevice.cpW, vdevice.transmat->m);
  41.  
  42.     vdevice.cpW[V_X] = x;
  43.     vdevice.cpW[V_Y] = y;
  44.     vdevice.cpW[V_Z] = z;
  45.     multvector(res, vdevice.cpW, vdevice.transmat->m);
  46.  
  47.     if (vdevice.clipoff) {    
  48.         vx = WtoVx(res);        /* just draw it */
  49.         vy = WtoVy(res);
  50.      
  51.         (*vdevice.dev.Vdraw)(vx, vy);
  52.  
  53.         vdevice.cpVx = vx;
  54.         vdevice.cpVy = vy;
  55.  
  56.         vdevice.cpVvalid = 0;
  57.     } else {
  58.         if (vdevice.cpVvalid)
  59.             quickclip(vdevice.cpWtrans, res);
  60.         else
  61.             clip(vdevice.cpWtrans, res);
  62.     }
  63.  
  64.     vdevice.cpWtrans[V_X] = res[V_X];
  65.     vdevice.cpWtrans[V_Y] = res[V_Y];
  66.     vdevice.cpWtrans[V_Z] = res[V_Z];
  67.     vdevice.cpWtrans[V_W] = res[V_W];
  68. }
  69.  
  70. /*
  71.  * draws
  72.  *
  73.  * draw a line form the logical graphics position to the
  74.  * the world coordinates x, y, z expressed as a short integer data type.
  75.  *
  76.  */
  77. void
  78. draws(x, y, z)
  79.     Scoord     x, y, z;
  80. {
  81.     draw((Coord)x, (Coord)y, (Coord)z);
  82. }
  83.  
  84.  
  85. /*
  86.  * drawi
  87.  *
  88.  * draw a line form the logical graphics position to the
  89.  * the world coordinates x, y, z expressed as an integer data type.
  90.  *
  91.  */
  92. void
  93. drawi(x, y, z)
  94.     Icoord     x, y, z;
  95. {
  96.     draw((Coord)x, (Coord)y, (Coord)z);
  97. }
  98.  
  99.  
  100.  
  101. /*
  102.  * draw2
  103.  *
  104.  * draw a line from the logical graphics position  to the
  105.  * the world coordinates x, y.
  106.  *
  107.  */
  108. void
  109. draw2(x, y)
  110.     double        x, y;
  111. {
  112.     if (!vdevice.initialised)
  113.         verror("draw2: vogl not initialised");
  114.  
  115.     draw(x, y, 0.0);
  116. }
  117.  
  118. /*
  119.  * draw2s
  120.  *
  121.  * draw a line from the logical graphics position  to the
  122.  * the world coordinates x, y expressed as a short integer data type.
  123.  *
  124.  */
  125. void
  126. draw2s(x, y)
  127.     Scoord     x, y;
  128. {
  129.     draw2((Coord)x, (Coord)y);
  130. }
  131.  
  132.  
  133. /*
  134.  * draw2i
  135.  *
  136.  * draw a line from the logical graphics position  to the
  137.  * the world coordinates x, y expressed as an integer data type.
  138.  *
  139.  */
  140. void
  141. draw2i(x, y)
  142.     Icoord     x, y;
  143. {
  144.     draw2((Coord)x, (Coord)y);
  145. }
  146.  
  147. /*
  148.  * rdr
  149.  *
  150.  * 3D relative draw from the logical graphics position by dx, dy, dz.
  151.  * This is the same as the VOGLE routine rdraw.
  152.  *
  153.  */
  154. void
  155. rdr(dx, dy, dz)
  156.     double        dx, dy, dz;
  157. {
  158.     if (!vdevice.initialised) 
  159.         verror("rdr: vogl not initialised");
  160.  
  161.     draw((vdevice.cpW[V_X] + dx), (vdevice.cpW[V_Y] + dy), (vdevice.cpW[V_Z] + dz));
  162. }
  163.  
  164. /*
  165.  * rdrs
  166.  *
  167.  * 3D relative draw from the logical graphics position by dx, dy, dz
  168.  * expressed as a short integer data type.
  169.  *
  170.  */
  171. void
  172. rdrs(dx, dy, dz)
  173.     Scoord    dx, dy, dz;
  174. {
  175.     rdr((Coord)dx, (Coord)dy, (Coord)dz);
  176. }
  177.  
  178. /*
  179.  * rdri
  180.  *
  181.  * 3D relative draw from the logical graphics position by dx, dy, dz
  182.  * expressed as an integer data type.
  183.  *
  184.  */
  185. void
  186. rdri(dx, dy, dz)
  187.     Icoord    dx, dy, dz;
  188. {
  189.     rdr((Coord)dx, (Coord)dy, (Coord)dz);
  190. }
  191.  
  192.  
  193. /*
  194.  * rdr2
  195.  *
  196.  * 2D relative draw from the logical graphics position by dx, dy.
  197.  * This is the same as the VOGLE routine rdraw2.
  198.  *
  199.  */
  200. void
  201. rdr2(dx, dy)
  202.     double        dx, dy;
  203. {
  204.     if (!vdevice.initialised) 
  205.         verror("rdr2: vogl not initialised");
  206.  
  207.     draw((vdevice.cpW[V_X] + dx), (vdevice.cpW[V_Y] + dy), 0.0);
  208. }
  209.  
  210.  
  211. /*
  212.  * rdr2s
  213.  *
  214.  * 3D relative draw from the logical graphics position by dx, dy
  215.  * expressed as a short integer data type.
  216.  *
  217.  */
  218. void
  219. rdr2s(dx, dy)
  220.     Scoord    dx, dy;
  221. {
  222.     rdr2((Coord)dx, (Coord)dy);
  223. }
  224.  
  225. /*
  226.  * rdr2i
  227.  *
  228.  * 3D relative draw from the logical graphics position by dx, dy
  229.  * expressed as an integer data type.
  230.  *
  231.  */
  232. void
  233. rdr2i(dx, dy)
  234.     Icoord    dx, dy;
  235. {
  236.     rdr2((Coord)dx, (Coord)dy);
  237. }
  238.  
  239.  
  240. /*
  241.  * bgnline
  242.  *
  243.  *     Flags that all v*() routine points will be building up a line list.
  244.  */
  245. void
  246. bgnline()
  247. {
  248.     if (vdevice.bgnmode != NONE)
  249.         verror("vogl: bgnline mode already belongs to some other bgn routine");
  250.  
  251.     vdevice.bgnmode = VLINE;
  252.     vdevice.save = 1;
  253. }
  254.  
  255. /*
  256.  * endline
  257.  *
  258.  *     Flags that all v*() routine points will be simply setting the 
  259.  *     current position.
  260.  */
  261. void
  262. endline()
  263. {
  264.     vdevice.bgnmode = NONE;
  265.     vdevice.save = 0;
  266. }
  267.  
  268. /*
  269.  * bgnclosedline
  270.  *
  271.  *     Flags that all v*() routine points will be building up a line list.
  272.  */
  273. void
  274. bgnclosedline()
  275. {
  276.     if (vdevice.bgnmode != NONE)
  277.         verror("vogl: bgncloseline mode already belongs to some other bgn routine");
  278.  
  279.     vdevice.bgnmode = VCLINE;
  280.     vdevice.save = 1;
  281. }
  282.  
  283. /*
  284.  * endclosedline
  285.  *
  286.  *     Flags that all v*() routine points will be simply setting the 
  287.  *     current position.
  288.  */
  289. void
  290. endclosedline()
  291. {
  292.     vdevice.bgnmode = NONE;
  293.     draw(vdevice.savex, vdevice.savey, vdevice.savez);
  294. }
  295.